package com.yanqu.road.server.manger.config;

import com.yanqu.road.logic.bussiness.config.CollectionBussiness;
import com.yanqu.road.entity.config.building.*;
import com.yanqu.road.server.TempMgr;
import com.yanqu.road.utils.RandomHelper;

import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

public class CollectionMgr extends TempMgr {

	private static final RandomHelper safeRandom = new RandomHelper();
    /**
     * 珍藏阁
     */
    private static Map<Integer, CollectionPavilion> collectionPavilionMap = new ConcurrentHashMap<>();
	/**
	 * 藏品
	 */
	private static Map<Integer, CollectionInfo> collectionInfoMap = new ConcurrentHashMap<>();
	/**
	 * 藏品升级表
	 */
	private static Map<Integer, CollectionUpgrade> collectionUpgradeMap = new ConcurrentHashMap<>();

	@Override
	public boolean stop() {
		return false;
	}

	@Override
	public boolean save() {
		return false;
	}

	@Override
	public boolean reloadConfig() {
		/*collectionPavilionMap = CollectionBussiness.getCollectionPavilionMap();
		if (collectionPavilionMap.size() <= 0) {
			return false;
		}

		collectionInfoMap = CollectionBussiness.getCollectionInfoMap();
		if (collectionInfoMap.size() <= 0) {
			return false;
		}

		collectionUpgradeMap = CollectionBussiness.getCollectionUpgradeMap();
		if(collectionUpgradeMap.size() <= 0){
			return false;
		}*/
		return true;
	}

	@Override
	public boolean reloadData() throws Exception {
		return true;
	}

	@Override
	public boolean init() throws Exception {
		return reload();
	}

	public static Map<Integer, CollectionInfo> getCollectionInfoMap() {
		return collectionInfoMap;
	}

	public static CollectionPavilion getCollectionPavilion(int level){
		return collectionPavilionMap.get(level);
	}

	public static CollectionUpgrade getCollectionUpgrade(int level){
		return collectionUpgradeMap.get(level);
	}

	public static boolean isCollectionUpgrade(CollectionUpgrade collectionUpgrade){
		int randomValue = safeRandom.next(0, 1000);
		return collectionUpgrade.getProbability() > randomValue;
	}
}
